package es.ats.codington.festival.junit.services;

import static org.junit.Assert.*;

import java.sql.Connection;
import java.util.ArrayList;

import junit.framework.TestCase;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import es.ats.codington.festival.daos.EventSignUpDAOImp;
import es.ats.codington.festival.domain.Event;
import es.ats.codington.festival.domain.EventSignUp;
import es.ats.codington.festival.services.EventSignUpService;
import es.ats.codington.festival.utils.FERSDataConnection;

public class tSignUpService extends TestCase{

	EventSignUp event;
	EventSignUpService eventService;
	Connection con;
	
	@Before
	protected void setUp() throws Exception {
		super.setUp();
		event= new EventSignUp(1,9);
		eventService = new EventSignUpService();
		con = FERSDataConnection.getConnection();
	}
		
	
	@After
	protected void tearDown() throws Exception {
		super.tearDown();
		con.close();
	}
	
	@Test
	public void testSignUpToEventService(){
		int nRow = 0;
		nRow = eventService.signUpToEvent(event.getUserId(),event.getEventId());
		assertEquals(1,nRow);
	}

	@Test
	public void testEventForUserService(){
		int nRow = 1;	
		ArrayList<Event> listIdEvents = new ArrayList<Event>();
		listIdEvents = eventService.eventForUserService(event.getUserId());
		if(listIdEvents.isEmpty())
			nRow=0;
		assertEquals(1,nRow);
	}
	@Test
	 public void testUnEventForUserService(){
		int nRow = 1;	
		ArrayList<Event> listIdEvents = new ArrayList<Event>();
		eventService.noEventForUserService(event.getUserId());
		if(listIdEvents.isEmpty())
			nRow=0;
		assertEquals(1,nRow);
	}
	@Test
	public void testUsignUpToEventService(){
		int nRow = 0;
		nRow = eventService.unsignUpToEvent(event.getUserId(),event.getEventId());
		assertEquals(1,nRow);
	}
}
